#include "HistoManager.hh"
#include "G4UnitsTable.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
HistoManager::HistoManager(G4String filename)
:fpRootFile(0),fpTree(0)
{
 fRootName = filename;
 fpEvt = new TEvent();
 book();
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

HistoManager::~HistoManager()
{
	//Save file
	save();
	fpRootFile->Close();
    if ( fpRootFile ) delete fpRootFile;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void HistoManager::book()
{ 
	//output file
 fpRootFile = new TFile(fRootName,"RECREATE");
 if(!fpRootFile) {
   G4cout << " HistoManager::book :" 
          << " problem creating the ROOT TFile "
          << G4endl;
   return;
 }

 //Tree
	fpTree = new TTree("t","Result");
	//fpTree->Branch("evt",&fpEvt,64000,0); //no auto-splitting
	fpTree->Branch("evt",&fpEvt);
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void HistoManager::save()
{ 
//	fpEvt->ShowEvent();
	fpTree->Write();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void HistoManager::PrintStatistic()
{
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void HistoManager::FillTree()
{
	fpTree->Fill();
}

